home *** CD-ROM | disk | FTP | other *** search
/ PC-Blue - MS DOS Public Domain Library / PC-Blue MS-DOS Public Domain Library - NYACC.iso / vol086 / roff44.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-12-15  |  5.7 KB  |  213 lines

  1. /********************************************************/
  2. /*                            */
  3. /*            ROFF4, Version 1.60            */
  4. /*                            */
  5. /*(C) 1983,4 by Ernest E. Bergmann            */
  6. /*        Physics, Building #16            */
  7. /*        Lehigh Univerisity            */
  8. /*        Bethlehem, Pa. 18015            */
  9. /*                            */
  10. /* Permission is hereby granted for all commercial and    */
  11. /* non-commercial reproduction and distribution of this    */
  12. /* material provided this notice is included.        */
  13. /*                            */
  14. /********************************************************/
  15. /*FEB 18, 1984*/
  16. /*JAN 15, 1984*/
  17. /********************************************************/
  18. /* March 1984  DeSmet C version */
  19. /* Henry Harpending*/
  20. /* Anthropology Department*/
  21. /* University of New Mexico*/
  22. /* Albuquerque, NM  87131*/
  23. /*   no restrictions */
  24. /*********************************************************/
  25. #include "a:roff4.h"
  26.  
  27. /**************************************************
  28. handles case of leading blanks or tabs; empty lines 
  29. ***************************************************/
  30. leadbl (line)
  31. char *line;
  32. {int i, j, white;
  33. brk();
  34. /* figure out white space Nov 13*/
  35. for (white=0, i=0; line[i] == ' ' || line[i] == '\t'; i++ )
  36.     {if(line[i]==' ') white++;
  37.     else white=min(RMVAL,TABSIZ*(1+white/TABSIZ));
  38.     }
  39. if ( line[i] != NEWLINE ) TIVAL += white;
  40. /* move line to left */
  41. for(j=0;(line[j]=line[i])!='\0';j++,i++);
  42. }
  43. /*****************************************
  44.         puts out page header
  45. ******************************************/
  46. phead()
  47. {exchange();
  48. UF=XF=FALSE;
  49. MCNT=1;
  50. CURPAG = NEWPAG++;
  51. if((CURPAG<FIRSTPAGE)||(CURPAG>LASTPAGE)) SUPPRESS=TRUE;
  52. else SUPPRESS=FALSE;
  53. OLDLN=-1;
  54. if(PAGESTOP)
  55.     {_os(2,7);    /*ring bell*/
  56.     _os(1);    /*wait til char typed at console*/
  57.     }
  58. PLINENO=0;FPLINENO=0;
  59. if (M1VAL > 0 )
  60.       { VLINENO = M1VAL-1;
  61.     if (CURPAG % 2) puttl3 ( OHEAD, OH2, OH3, CURPAG );
  62.     else puttl3 ( EHEAD, EH2, EH3, CURPAG );
  63.       }
  64. VLINENO = M1VAL+M2VAL; FVLINENO=0;
  65. exchange();
  66. }
  67. /**************************************
  68.         puts out page footer
  69. ***************************************/
  70. pfoot()
  71. {exchange();
  72. UF=XF=FALSE;
  73. MCNT=1;
  74. VLINENO = BOTTOM+M3VAL; FVLINENO=0;
  75. if ( M4VAL > 0 )
  76.       { if(CURPAG % 2)puttl3 ( OFOOT,OF2,OF3, CURPAG );
  77.     else puttl3(EFOOT,EF2,EF3,CURPAG);
  78.       }
  79. VLINENO = PLVAL;FVLINENO=0;
  80. if (FFEED) cputc(FORMF,ofp);
  81. else padv();
  82. whole();
  83. OLDBOT=PLINENO=FPLINENO=0;/*printer at start of newpage*/
  84. OLDLN=-1;
  85. exchange();
  86. }
  87. /**********************************************
  88.     space n lines or to bottom of the page
  89. ***********************************************/
  90. space (n)
  91. int n;
  92. {brk();    /* flush out last unfilled line */
  93. if (VLINENO >= BOTTOM)    return;    /* end of page */
  94. if (VLINENO<0) phead();    /* top of page */
  95. VLINENO += n;
  96. if (VLINENO >= BOTTOM) pfoot(); /* print footer if bottom */
  97. }
  98. /*******************************************************/
  99. text (line)
  100. char *line;
  101. {char wrdbuf [LSZ];
  102. int i, j, k;
  103. char *p1, *p2;
  104. if DEBUG fprintf(stderr,"\n\nTEXT:<%s>", line);
  105. if (line[0] == BLANK || line[0]==NEWLINE || line[0] == TAB)
  106.     leadbl (line);
  107. if (CEVAL > 0)
  108.       { center(line);
  109.     put(line);
  110.     CEVAL--;
  111.       }
  112. else if(line[0]==NEWLINE) space(LSVAL);
  113. else if(!FILL) put(line);
  114. else while (WE_HAVE_A_WORD == getwrd (line, wrdbuf))
  115.     putwrd (wrdbuf);
  116. }
  117. /******************************************************
  118.     put out a line of text with correct indentation
  119.     underlining if specified
  120. *******************************************************/
  121. put (line)
  122. char *line;
  123. {int i,fs,minfs;
  124. if ((VLINENO < 0)||(VLINENO >= BOTTOM)) phead();
  125. fs=(VLINENO-OLDLN)*FRVAL;
  126. minfs=OLDBOT-OUTTOP; if(!(OLDBOT&&OUTTOP)) minfs++;
  127. while(fs<minfs) {fs+=FRVAL; VLINENO++;}
  128. need(0);
  129. putline(line);
  130. TIVAL = INVAL;
  131. VLINENO += LSVAL;
  132. if (VLINENO >= BOTTOM) pfoot();
  133. }
  134. /***********************************************************
  135. concatenates the word onto the end of OUTBUF for filled text
  136. ************************************************************/
  137. putwrd (wrdbuf)    /*Nov 22: SENTENCE*/
  138. char *wrdbuf;
  139. {int i, j, k;
  140. char s[MAXLINE], ch;
  141. int line_len, new_out_width, wid;
  142. int nextra;
  143. skip_blanks (wrdbuf); trunc_bl (wrdbuf);
  144. wid =1+SENTENCE+strln3(wrdbuf,TRUE,1);/*sets WTOP,WBOT*/
  145. line_len = RMVAL - TIVAL;
  146. new_out_width = OUTW+wid;
  147. if (new_out_width > min (line_len, MAXLINE-1))
  148.       { nextra = min(line_len, MAXLINE-1)-OUTW+1;
  149.     if(OUTBUF[OUTPOS-2]==BLANK) nextra++;
  150.     if(JUSTIFY) spread(OUTBUF,nextra,OUTWRDS);
  151.     brk();
  152.       }
  153. OUTW += wid;
  154. OUTcat(wrdbuf);
  155. OUTSP(); if(SENTENCE) OUTSP();
  156. OUTWRDS++;
  157. if(WTOP<OUTTOP) OUTTOP=WTOP;
  158. if(WBOT>OUTBOT) OUTBOT=WBOT;
  159. }
  160. /**********************************************************
  161.     a new putline routine; sends line to  OUTPUT2
  162. ***********************************************************/
  163. putline (line)
  164. char *line;
  165. {char c;
  166. blanks(TIVAL);
  167. for(;c=*line;line++) putout(c);
  168. putout('\0');
  169. printout();
  170. }
  171. /****************************************/
  172. OUTcat(str)    /*appends string to OUTBUF*/
  173. char *str;
  174. {while(OUTBUF[OUTPOS]=*(str++))
  175.     OUTPOS++;
  176. }
  177. /****************************************/
  178. OUTSP()        /*appends BLANK to OUTBUF*/
  179. {OUTBUF[OUTPOS++]=BLANK;
  180. OUTBUF[OUTPOS]='\0';
  181. }
  182. /****************************************/
  183. gloss()    /*prints on STDOUT a glossary of .tr chars*/
  184. {int i;
  185. char line[20],tcs;
  186. put("GLOSSARY:");
  187. put("USE     <GET>");
  188. tcs=TCVAL;
  189. TCVAL |= 128; /*set most significant bit*/
  190. for(i=1;i<19;i++) line[i]=' ';
  191. line[0]=tcs;
  192. line[8]='<';
  193. line[9]=TCVAL;
  194. line[11]='>';
  195. line[12]='\0';
  196. for(i=' ';i<127;i++)
  197.     {if(TPTR[i-' '])
  198.         {line[1]=line[10]=i;
  199.         put(line);
  200.         }
  201.     }
  202. TCVAL=tcs;
  203. SPACE(HUGE);
  204. }
  205. /***************************************/
  206. exchange() /*maintain separate environment for headers and
  207.         footers*/
  208. {int i;
  209. i=MCNT2; MCNT2=MCNT; MCNT=i;
  210. i=XF2; XF2=XF; XF=i;
  211. i=UF2; UF2=UF; UF=i;
  212. }
  213.